import os
import datetime
def load_conf_labels():
    script_label_id={}
    name_label_id={}
    label_name={}
    script_label_dic={}
    name_label_dic={}
    with open("label.conf","r") as fr:
        for line in fr:
            values=line.strip().split("_")
            #print(values)
            if len(values) !=4 :
                continue
            #print(values)
            #all_labels.append({"labelName":values[0],"labelId":values[1]})
            script_label_id[values[0]]=int(values[2])
            name_label_id[values[0]]=int(values[3])
    #print(len(label_id))
    with open("label_english_name.conf","r") as fr:
        for line in fr:
            values=line.strip().split("@")
            #print(values)
            if len(values) != 2:
                #print(values)
                continue
            #print(values)
            #all_labels.append({"labelName":values[0],"labelId":values[1]})
            label_name[values[0]]=values[1]
    #print(script_label_id)
    #print(label_name)
    for key in script_label_id:
        if key in label_name:
            #print(label_name[key])
            script_label_dic[label_name[key]] = script_label_id[key]
            name_label_dic[label_name[key]] = name_label_id[key]
        #else:
            #print(key)
    #print(len(label_dic))
    return script_label_dic,name_label_dic

class predict():
    def __init__(self,data,maxvalue):
        #活动减免额度
        self.now_reduce_price = data['now_reduce_price']
        #是否流量超套餐
        self.is_gprs_over = data["is_gprs_over"]
        #是否语音超套餐
        self.is_gsm_over = data["is_gsm_over"]
        #当月总使用流量
        self.gprs_all = data["gprs_all"]
        #当月总使用语音
        self.gsm_all = data["gsm_all"]
        #当月剩余流量
        self.gprs_residua = data["gprs_residua"]
        #当月剩余语音
        self.gsm_residua = data["gsm_residua"]
        #当月日均使用流量
        self.avg_day_gprs = data["avg_day_gprs"]
        #当月日均使用语音
        self.avg_day_gsm = data["avg_day_gsm"]
        #当前距月末几天
        self.suf_cur_day_count = data["suf_current_day_count"]
        #近三个月语音超套次数
        self.avg_three_month_gsm_count = data["avg_three_month_gsm_count"]
        #近三个月流量超套次数
        self.avg_three_month_gprs_count = data["avg_three_month_gprs_count"]
        #近三个月平均套外流量费
        self.avg_three_month_gprs_fee = data["avg_three_month_gprs_fee"]
        #近三个月平均套外语音费
        self.avg_three_month_gsm_fee = data["avg_three_month_gsm_fee"]
        self.bill_fee1 = data["bill_fee1"]
        self.bill_fee2 = data["bill_fee2"]
        self.bill_fee3 = data["bill_fee3"]
        #近三个月平均套外语音使用量
        self.avg_three_month_gsm = data["avg_three_month_gsm"]
        #近三个月平均套外流量使用量
        self.avg_three_month_gprs = data["avg_three_month_gprs"]
        #账务月套外上网费
        self.tcw_gprs_fee1 = data["tcw_gprs_fee1"]
        #账务月套外语音费
        self.tcw_gsm_fee1 = data["tcw_gsm_fee1"]
        #账外月套内总使用流量
        self.gprs_main_all1 = data["gprs_main_all1"]
        self.gprs_main_all2 = data["gprs_main_all2"]
        self.gprs_main_all3 = data["gprs_main_all3"]
        #账务月套外上网使用量
        self.tcw_gprs1 = data["tcw_gprs1"]
        self.gsm_main_all1 = data['gsm_main_all1']
        self.gsm_main_all2 = data['gsm_main_all2']
        self.gsm_main_all3 = data['gsm_main_all3']
        #账务月总使用语音量
        self.gsm_zj1 = data["gsm_zj1"]
        #账务月套外总使用语音量
        self.tcw_gsm1 = data["tcw_gsm1"]
        #账务月减一套外上网费
        self.tcw_gprs_fee2 = data["tcw_gprs_fee2"]
        #账务月减一套外语音费
        self.tcw_gsm_fee2 = data["tcw_gsm_fee2"]
        #账务月减一套外上网流量
        self.tcw_gprs2 = data["tcw_gprs2"]
        #账务月减一套外语音使用量
        self.tcw_gsm2 = data["tcw_gsm2"]
        #账务月减二套外上网费
        self.tcw_gprs_fee3 = data["tcw_gprs_fee3"]
        #账务月减二套外语音费
        self.tcw_gsm_fee3 = data["tcw_gsm_fee3"]
        #账务月减二套外上网流量
        self.tcw_gprs3 = data["tcw_gprs3"]
        #账务月减二套外语音使用量
        self.tcw_gsm3 = data["tcw_gsm3"]
        #是否有活动到期
        self.over_activity = data["is_over_activity"]
        #上个月失效活动个数
        self.pre_day_count = data["pre_day_num"]
        #本月失效活动个数
        self.current_month_count = data["current_month_num"]
        #次日失效活动个数
        self.next_day_count = data["next_day_num"]
        #次月失效活动个数
        self.next_month_count = data["next_month_num"]
        #主套餐资费
        self.now_prod_value = data["now_prod_value"]
        #主套餐包含流量
        self.now_prod_gprs = data["now_prod_gprs"]
        #主套餐包含语音
        self.avg_three_month_shorttime_packet_ordertime = data["avg_three_month_shorttime_packet_ordertime"]
        self.now_prod_gsm = data["now_prod_gsm"]
        #当月总使用流量
        self.gprs_all = data["gprs_all"]
        self.gprs_all1 = data["gprs_all1"]
        self.gprs_all2 = data["gprs_all2"]
        self.gprs_all3 = data["gprs_all3"]
        #当月总使用语音
        self.gsm_all = data["gsm_all"]
        #self.data_content = data["data_content"]
        self.three_month_gprs_limit = data['is_limit']
        self.productDesc = data["productDesc"]
        #坐席勾选的场景标签
        self.label_list = {"cur_month_gsm_over":1,"cur_month_gprs_over":1,"two_last_month_gsm_over":1,"two_last_month_gprs_over":1,"cur_month_gsm_will_over":1,"cur_month_gprs_will_over":1,"three_month_gsm_over":1,"three_month_gprs_over":1,"last_month_gsm_over":1,"last_month_gprs_over":1,"over_activity":1,"pre_day_num":1,"current_month_num":1,"next_day_num":1,"next_month_num":1}
    #当月语音是否超套
        self.label_name_value =maxvalue
    
    def is_high_user(self,set_now_prod_value=12800):
        if self.now_prod_value > set_now_prod_value and self.bill_fee1 >= self.now_prod_value and (self.gprs_all1 > self.now_prod_gprs or self.gsm_zj1 >self.now_prod_gsm):
            return True
        return False
    def is_low_gsm_gprs(self):
        if self.now_prod_gprs < 3000 and self.now_prod_gsm < 40:
            if (self.now_prod_gprs < self.gprs_main_all1 or self.now_prod_gsm <self.gsm_main_all1) and (self.gsm_residua < 0.5*self.now_prod_gsm or self.gsm_residua < 0.5*self.now_prod_gsm):
                return True
            if (self.now_prod_gprs - self.gprs_main_all1 < 0.1*self.now_prod_gprs or self.now_prod_gsm -self.gsm_main_all1 < 0.1*self.now_prod_gsm) and (self.gsm_residua < 0.5*self.now_prod_gsm or self.gsm_residua < 0.5*self.now_prod_gsm):
                return True
        return False
    def is_gprs_used_growth(self):
        if self.gprs_all1 > self.gprs_all2 and self.gprs_all2 > self.gprs_all3 and self.gprs_residua < 0.5*self.now_prod_gprs:
            return True
        return False
    def is_gsm_used_growth(self):
        #if self.now_prod_gsm-self.gsm_main_all1 > self.gsm_main_all1 -self.gsm_main_all2:
        if self.gsm_zj1 > self.gsm_zj2 and self.gsm_zj2 > self.gsm_zj3 and self.gsm_residua < 0.5*self.now_prod_gsm:
            return True
        return False
    def is_high_gprs_low_gsm(self):
        #if (self.now_prod_gprs - self.gprs_main_all1)/self.now_prod_gprs > 0.4 and self.now_prod_gprs >15000:
            #return True
        if self.now_prod_gsm - self.gsm_main_all1 <= 0.2*self.now_prod_gsm and self.now_prod_gsm - self.gsm_main_all2 <= 0.2*self.now_prod_gsm and self.now_prod_gsm - self.gsm_main_all3 <= 0.2*self.now_prod_gsm:
            if self.gsm_residua < 0.5*self.now_prod_gsm:
                return True
        return False
    def is_high_gsm_low_gprs(self):
        #if (self.now_prod_gsm - self.gsm_main_all1)/self.now_prod_gsm > 0.4 and self.now_prod_gsm >20:
            #return True
        if self.now_prod_gprs - self.gprs_main_all1 <= 0.2*self.now_prod_gprs and self.now_prod_gprs - self.gsm_main_all2 <= 0.2*self.now_prod_gprs and self.now_prod_gprs - self.gsm_main_all3 <= 0.2*self.now_prod_gprs:
            if self.gprs_residua < 0.5*self.now_prod_gprs:
                return True
        return False
    def is_reduce_user(self):
        if self.now_prod_value> 1900 and self.now_reduce_price/self.now_prod_value >0.10 and (self.gprs_residua < 0.5*self.now_prod_gprs or self.gsm_residua < 0.5*self.now_prod_gsm):
            return True
        return False
    #账务月流量使用大于主套餐包含流量
    def is_gprs_over_now_prod(self):
        if self.gprs_all1 > self.now_prod_gprs and self.tcw_gprs_fee1 <= 0 and self.gprs_residua < 0.5*self.now_prod_gprs:
            return True
        return False
    #账务月语音使用大于主套餐包含语音
    def is_gsm_over_now_prod(self):
        if self.gsm_zj1 > self.now_prod_gsm and self.tcw_gsm_fee1 <= 0 and self.gsm_residua < 0.5*self.now_prod_gsm:
            return True
        return False
    
    def is_cur_month_gprs_over(self,gprs_over_value =1):
        #print(gprs_over_value)
        if self.is_gprs_over >= 1 and gprs_over_value == 1:
            return True
        elif self.gprs_all - self.now_prod_gprs >= gprs_over_value and gprs_over_value !=1:
            return True
        return False
    #当月流量是否超套
    def is_cur_month_gsm_over(self,gsm_over =1):
        if self.is_gsm_over >=1 and gsm_over==1:
            return True
        elif self.gsm_all- self.now_prod_gsm>= gsm_over and gsm_over !=1:
            return True
        return False
    #账务月流量超套
    def is_last_month_gprs_over(self,tcw_gprs1_value=0):
        if  self.tcw_gprs1 > tcw_gprs1_value:
            return True
        if self.tcw_gprs_fee1 > 0 and tcw_gprs1_value==0:
            return True
        return False
    #账务月语音超套
    def is_last_month_gsm_over(self,tcw_gsm1_value =0): 
        if  self.tcw_gsm1 > tcw_gsm1_value:
            return True
        if self.tcw_gsm_fee1 > 0 and tcw_gsm1_value==0:
            return True
        return False
    #近三个月流量均超套
    def is_three_month_gprs_over(self):
        prod = self.is_last_month_gprs_over() + self.is_two_last_month_gprs_over() +self.is_three_last_month_gprs_over()
        if self.avg_three_month_gprs_count > prod:
            return self.avg_three_month_gprs_count
        elif self.avg_three_month_gprs_count <= prod and prod >0:
            return prod
        return 0
    #近三个月语音均超套
    def is_three_month_gsm_over(self):
        prod = self.is_last_month_gsm_over() + self.is_two_last_month_gsm_over() +self.is_three_last_month_gsm_over()
        if self.avg_three_month_gsm_count > prod:
            return self.avg_three_month_gsm_count
        elif self.avg_three_month_gsm_count <= prod and prod >0:
            return prod
        return 0
    #当月流量预将超套
    def is_cur_month_gprs_will_over(self):
        #print("当月流量预将超套")
        if self.now_prod_gprs <= 0 or self.suf_cur_day_count <= 0:
            return False
        if self.gprs_residua/self.now_prod_gprs < 0.3 and self.gprs_residua / self.suf_cur_day_count < self.avg_day_gprs and self.gprs_residua / self.suf_cur_day_count < 0.01:
            return True
        return False
    #当月语音预将超套
    def is_cur_month_gsm_will_over(self):
        #print("当月语音预将超套")
        if self.now_prod_gsm <= 0 or self.suf_cur_day_count <= 0:
            return False
        if self.gsm_residua/self.now_prod_gsm < 0.15 and self.gsm_residua / self.suf_cur_day_count < self.avg_day_gsm and self.gsm_residua/self.suf_cur_day_count < 2 :
            return True
        return False
    def is_will_over_level(self):
        if self.suf_cur_day_count<=10:
            return 1
        elif self.suf_cur_day_count>=10 and self.suf_cur_day_count<=20:
            return 2
        else:
            return 3
    #上个账务月流量超套
    def is_two_last_month_gprs_over(self,tcw_gprs2_value =0 ):
        if self.tcw_gprs2 > tcw_gprs2_value:
            return True
        if self.tcw_gprs_fee2 > 0 and tcw_gprs2_value ==0:
            return True
        return False
    
    #上个账务月语音超套
    def is_two_last_month_gsm_over(self,tcw_gsm2_value=0): 
        if  self.tcw_gsm2 > tcw_gsm2_value:
            return True
        if self.tcw_gsm_fee2 > 0 and tcw_gsm2_value==0:
            return True
        return False
    #上上个帐务月流量超套
    def is_three_last_month_gprs_over(self,tcw_gprs3_value=0):
        if self.tcw_gprs3 > tcw_gprs3_value :
            return True
        if self.tcw_gprs_fee3 > 0 and tcw_gprs3_value==0:
            return True
        return False
    
    #上上个账务月语音超套
    def is_three_last_month_gsm_over(self,tcw_gsm3_value = 0):
        if  self.tcw_gsm3 > tcw_gsm3_value:
            return True
        if self.tcw_gsm_fee3 > 0 and tcw_gsm3_value == 0:
            return True
        return False
    #超套类level计算
    def is_over_fee_level(self,over_fee):
        if over_fee <= 1:
            return 1
        elif over_fee >= 1 and over_fee >= 1 and over_fee <= 5:
            return 2
        else:
            return 3
    
    #活动到期
    def is_over_activity(self):
        if self.pre_day_count > 0 or self.current_month_count > 0 or self.next_day_count > 0 or self.next_month_count > 0:
            return 1
        return 0
    #上月有办理的活动已到期
    def is_pre_day_num(self):
        if  self.pre_day_count > 0:
            #return self.pre_day_count
            return 1
        return 0
    #本月有办理的活动将到期
    def is_current_month_num(self):
        if  self.current_month_count > 0:
            #return self.current_month_count
            return 1
        return 0
    #次日有办理的活动将到期
    def is_next_day_num(self):
        if self.next_day_count>0:
            return 1
        return 0
    #次月有办理的活动将到期
    def is_next_month_num(self):
        if self.next_month_count>0:
            return 1
        return 0
    def product_cur_month_gsm(self,script_label_dic,name_label_dic,label_words):
        if "cur_month_gsm_over" in self.label_name_value and self.is_cur_month_gsm_over(self.label_name_value["cur_month_gsm_over"]):
            level = self.is_will_over_level()
            if script_label_dic["cur_month_gsm_over"] >= 1:
                script_label_dic["cur_month_gsm_over"] = level
            else:
                script_label_dic["cur_month_gsm_over"] = 0
            value = self.gsm_all - self.now_prod_gsm
            if name_label_dic["cur_month_gsm_over"] >= 1 and value > 0:
                name_label_dic["cur_month_gsm_over"] = level
                
                label_words["cur_month_gsm_over"] = "当月语音已超套" +self.conver_time(value)
            else:
                name_label_dic["cur_month_gsm_over"] = 0
            
        elif self.is_cur_month_gsm_over():
            level = self.is_will_over_level()
            if script_label_dic["cur_month_gsm_over"] >= 1:
                script_label_dic["cur_month_gsm_over"] = level
            else:
                script_label_dic["cur_month_gsm_over"] = 0
            value = self.gsm_all - self.now_prod_gsm
            if name_label_dic["cur_month_gsm_over"] >= 1 and value >0:
                name_label_dic["cur_month_gsm_over"] = level
                
                label_words["cur_month_gsm_over"] = "当月语音已超套" +self.conver_time(value)
            else:
                name_label_dic["cur_month_gsm_over"] = 0
        else:
            if self.is_cur_month_gsm_will_over():
                level = self.is_will_over_level()
                if script_label_dic["cur_month_gsm_will_over"] >= 1:
                    script_label_dic["cur_month_gsm_will_over"] = level
                else:
                    script_label_dic["cur_month_gsm_will_over"] = 0
                value = self.avg_day_gsm*self.suf_cur_day_count - self.gsm_residua
                if name_label_dic["cur_month_gsm_will_over"] >= 1 and value>0:
                    name_label_dic["cur_month_gsm_will_over"] = level
                    
                    label_words["cur_month_gsm_will_over"] = "当月语音预超套" +self.conver_time(value)
                else:
                    name_label_dic["cur_month_gsm_will_over"] = 0
        return script_label_dic,name_label_dic,label_words
    def product_cur_month_gprs(self,script_label_dic,name_label_dic,label_words):
        if "cur_month_gprs_over" in self.label_name_value and self.is_cur_month_gprs_over(self.label_name_value["cur_month_gprs_over"]):
            #print(self.label_name_value["cur_month_gprs_over"])
            #print("start11")
            level = self.is_will_over_level()
            if script_label_dic["cur_month_gprs_over"] >= 1:
                script_label_dic["cur_month_gprs_over"] = level
            else:
                script_label_dic["cur_month_gprs_over"] = 0
            value = self.gprs_all - self.now_prod_gprs
            if name_label_dic["cur_month_gprs_over"] >= 1 and value > 0:
                name_label_dic["cur_month_gprs_over"] = level
                
                label_words["cur_month_gprs_over"] = "当月流量已超套" +self.conver_m(value)
            else:
                name_label_dic["cur_month_gprs_over"] = 0
        elif self.is_cur_month_gprs_over() and "cur_month_gprs_over" not in self.label_name_value:
            #print("start22")
            level = self.is_will_over_level()
            if script_label_dic["cur_month_gprs_over"] >= 1:
                script_label_dic["cur_month_gprs_over"] = level
            else:
                script_label_dic["cur_month_gprs_over"] = 0
            value = self.gprs_all - self.now_prod_gprs
            if name_label_dic["cur_month_gprs_over"] >= 1 and value > 0:
                name_label_dic["cur_month_gprs_over"] = level
                label_words["cur_month_gprs_over"] = "当月流量已超套" +self.conver_m(value)
            else:
                name_label_dic["cur_month_gprs_over"] = 0
        else:
            if self.is_cur_month_gprs_will_over():
                level = self.is_will_over_level()
                if script_label_dic["cur_month_gprs_over"] >= 1:
                    script_label_dic["cur_month_gprs_over"] = level
                else:
                    script_label_dic["cur_month_gprs_over"] = 0
                value = self.avg_day_gprs*self.suf_cur_day_count - self.gprs_residua
                if name_label_dic["cur_month_gprs_over"] >= 1 and value > 0:
                    name_label_dic["cur_month_gprs_over"] = level    
                    label_words["cur_month_gprs_over"] = "当月流量预超套" +self.conver_m(value)
                else:
                    name_label_dic["cur_month_gprs_over"] = 0
        return script_label_dic,name_label_dic,label_words

    def predict_label(self):
        '''label_dict = {"cur_month_gsm_over":0,"cur_month_gprs_over":0,"two_last_month_gsm_over":0,
                      "two_last_month_gprs_over":0,"cur_month_gsm_will_over":0,"cur_month_gprs_will_over":0,
                    "three_month_gsm_over":0,"three_month_gprs_over":0,"last_month_gsm_over":0,
                    "last_month_gprs_over":0,"pre_day_num":0,"current_month_num":0,
                    "next_day_num":0,"next_month_num":0,
                    "three_last_month_gsm_over":0,
                    "three_last_month_gprs_over":0,
                    "three_month_gprs_use":0,
                    "three_month_gprs_percent":0,
                    "three_month_avg_fee":0,
                    }'''
        script_label_dic,name_label_dic = load_conf_labels()
        label_words ={}
        #print(name_label_dic)
        #print(self.label_name_value)
        script_label_dic,name_label_dic,label_words = self.product_cur_month_gsm(script_label_dic,name_label_dic,label_words)
        script_label_dic,name_label_dic,label_words = self.product_cur_month_gprs(script_label_dic,name_label_dic,label_words)
        if self.is_three_month_gsm_over()>0:
            level = self.is_over_fee_level(self.tcw_gsm_fee1+self.tcw_gsm_fee2+self.tcw_gsm_fee3)
            if script_label_dic["three_month_gsm_over"] >= 1:
                script_label_dic["three_month_gsm_over"] = level
            else:
                script_label_dic["three_month_gsm_over"] = 0
            if name_label_dic["three_month_gsm_over"] >= 1:
                name_label_dic["three_month_gsm_over"] = level
                label_words["three_month_gsm_over"] = "近三个月语音超套" +str(self.is_three_month_gsm_over()) + "次" 
            else:
                name_label_dic["three_month_gsm_over"] = 0
        if self.is_three_month_gprs_over()>0:
            level = self.is_over_fee_level(self.tcw_gprs_fee1+self.tcw_gprs_fee2+self.tcw_gprs_fee3)
            if script_label_dic["three_month_gprs_over"] >= 1:
                script_label_dic["three_month_gprs_over"] = level 
            else:
                script_label_dic["three_month_gprs_over"] = 0
            if name_label_dic["three_month_gprs_over"] >= 1:
                name_label_dic["three_month_gprs_over"] = level 
                label_words["three_month_gprs_over"] = "近三个月流量超套" +str(self.is_three_month_gprs_over()) + "次" 
            else:
                name_label_dic["three_month_gprs_over"] = 0
            
        #label_dict["over_activity"] = self.is_over_activity()
        #label_dict["over_activity"] = 0
        if script_label_dic['three_month_gprs_limit'] >= 1 and self.three_month_gprs_limit > 0:
            script_label_dic['three_month_gprs_limit'] = 1
        if name_label_dic['three_month_gprs_limit'] >= 1 and self.three_month_gprs_limit > 0:
            name_label_dic['three_month_gprs_limit'] = 1
            label_words['three_month_gprs_limit'] = "近三个月流量限速" +str(self.three_month_gprs_limit) + "次"
        if script_label_dic["pre_day_num"] >= 1 and self.is_pre_day_num() > 0:
            script_label_dic["pre_day_num"] = 1
        if name_label_dic["pre_day_num"] >= 1 and self.is_pre_day_num() > 0:
            name_label_dic["pre_day_num"] = 1
            label_words['pre_day_num'] = "上月活动到期数量" + str(self.is_pre_day_num()) + "个"
        if script_label_dic["current_month_num"] >= 1 and self.is_current_month_num() > 0:
            script_label_dic["current_month_num"] = 1
        if name_label_dic["current_month_num"] >= 1 and self.is_current_month_num() > 0:
            name_label_dic["current_month_num"] = 1
            label_words['current_month_num'] = "本月活动到期数量" + str(self.is_current_month_num()) + "个"
        if script_label_dic["next_day_num"] >= 1 and self.is_next_day_num() > 0:
            script_label_dic["next_day_num"] = 1
        if name_label_dic["next_day_num"] >= 1 and self.is_next_day_num() > 0:
            name_label_dic["next_day_num"] = 1
            label_words['next_day_num'] = "次日活动到期数量" + str(self.is_next_day_num()) + "个"
        if script_label_dic["next_month_num"] >= 1 and self.is_next_month_num()> 0:
            script_label_dic["next_month_num"] = 1
        if name_label_dic["next_month_num"] >= 1 and self.is_next_month_num()> 0:
            name_label_dic["next_month_num"] = 1
            label_words['next_month_num'] = "下月活动到期数量" + str(self.is_next_month_num()) + "个"
        if name_label_dic["avg_three_month_shorttime_packet_ordertime"] >= 1 and len(self.avg_three_month_shorttime_packet_ordertime) > 0:
            name_label_dic["avg_three_month_shorttime_packet_ordertime"] = 1
            label_words["avg_three_month_shorttime_packet_ordertime"] = "近三个月短时流量包订购" + str(len(self.avg_three_month_shorttime_packet_ordertime)) + "次"
        if name_label_dic["three_month_avg_fee"] >= 1 and self.bill_fee1+self.bill_fee2+self.bill_fee3 > 0:
            name_label_dic["three_month_avg_fee"] = 1
            label_words['three_month_avg_fee'] = "近三个月平均消费"+self.conver_yuan(self.bill_fee1+self.bill_fee2+self.bill_fee3)
        if name_label_dic["three_month_gprs_use"] >= 1 and self.gprs_all1 + self.gprs_all2 + self.gprs_all3 > 0:
            name_label_dic["three_month_gprs_use"] = 1
            label_words['three_month_gprs_use'] = "近三个月平均流量使用"+self.conver_m((self.gprs_all1 + self.gprs_all2 + self.gprs_all3)/(3*1024.0)) 
        if script_label_dic["high_prod_user"] >= 1  and self.is_high_user():
            script_label_dic["high_prod_user"] = 2
        if script_label_dic["low_gsm_gprs"] >= 1  and self.is_low_gsm_gprs():
            script_label_dic["low_gsm_gprs"] = 2
        if script_label_dic["gprs_used_growth"]  and self.is_gprs_used_growth():
            script_label_dic["gprs_used_growth"] = 2
        if script_label_dic["gsm_used_growth" ] >= 1 and self.is_gsm_used_growth():
            script_label_dic["gsm_used_growth"] = 2
        if script_label_dic["high_gprs_low_gsm"] >= 1  and self.is_high_gprs_low_gsm():
            script_label_dic["high_gprs_low_gsm"] = 2
        if self.is_high_gsm_low_gprs():
            if script_label_dic["three_month_gprs_enough"]  >= 1:
                script_label_dic["three_month_gprs_enough"] = 2
            if name_label_dic["three_month_gprs_enough"]  >= 1:
                script_label_dic["three_month_gprs_enough"] = 2
                if self.now_prod_gprs > 0:
                    label_words['three_month_gprs_enough'] = "近三个月流量饱和度"+str(((self.gprs_all1 + self.gprs_all2 + self.gprs_all3)/(3*self.now_prod_gprs))*100) + "%"
                
        if script_label_dic["reduce_user"] >= 1  and self.is_reduce_user():
            script_label_dic["reduce_user"] = 2
        if script_label_dic["gprs_over_now_prod"] >= 1  and self.is_gprs_over_now_prod():
            script_label_dic["gprs_over_now_prod"] = 2
        if script_label_dic["gsm_over_now_prod"] >= 1  and self.is_gsm_over_now_prod():
            script_label_dic["gsm_over_now_prod"] = 2
        
        
        #print(label_dict)
        #print("ending predict")
        return script_label_dic,name_label_dic,label_words
    def conver_m(self,value):
        if value>=1024:
            return str(round(float(value)/1024.0,2)) + "G"
        return str(value) + "M"
    def conver_yuan(self,value):    
        return str(round(float(value)/100.0,2)) + "元"
    def conver_time(self,value):
        return str(value)+"分钟"
    def product_over_gprs(self,value1,value2):
        temp=""
        if value1>0:
            temp+="超出流量"+self.conver_m(value1)
        if value2>0:
            if temp =="":
                temp=","
            temp+="超出额外流量费"+self.conver_yuan(value2)
        return temp
    def product_over_gsm(self,value1,value2):
        temp=""
        if value1>0:
            temp+="超出语音"+self.conver_time(value1)
        if value2>0:
            if temp!="":
                temp=","
            temp+="超出额外流量费"+self.conver_yuan(value2)
        return temp
    def compute_level_script(self):
        script_label_dic,name_label_dic,label_words = self.predict_label()
        label_level = {"cur_month_over":0,"three_month_over":0,"cur_month_will_over":0,"activate_over":0}
        label_script = {}
        gsm_fee = 0
        gprs_fee = 0
        if script_label_dic["cur_month_gsm_over"]>0 and script_label_dic["cur_month_gsm_over"]>0:
            label_script['cur_month_over'] = "尊敬的用户，你好，观察到你当月的消费情况，本月语音流量均已超套," +"语音使用" + self.conver_time(self.gsm_all)+"；流量使用" + self.conver_m(self.gprs_all) 
            level = 1+int((gsm_fee+gsm_fee)/5)
            label_level["cur_month_over"]
        elif script_label_dic["cur_month_gsm_over"]>0 :
            label_script['cur_month_over'] = "尊敬的用户，你好，观察到你当月的消费情况，本月语音流量均已超套," +"语音使用" + self.conver_time(self.gsm_all)
            level = 1+int((gsm_fee+gsm_fee)/5)
            label_level["cur_month_over"]
        elif script_label_dic["cur_month_gsm_over"]>0:
            label_script['cur_month_over'] = "尊敬的用户，你好，观察到你当月的消费情况，本月语音流量均已超套," +"流量使用" + self.conver_m(self.gprs_all) 
            level = 1+int((gsm_fee+gsm_fee)/5)
            label_level["cur_month_over"]
        gprs = self.is_three_month_gprs_over()
        gsm = self.is_three_month_gsm_over()
        gsm_fee = self.tcw_gsm_fee1+self.tcw_gsm_fee2+self.tcw_gsm_fee3
        gprs_fee = self.tcw_gprs_fee1+self.tcw_gprs_fee2+self.tcw_gprs_fee3
        if  gprs > 0 and gsm > 0:
            label_script["three_month_over"] = "观察到你近三月语音流量使用情况，" + "语音超套" + str(gsm) + "次，" + self.product_over_gsm(self.tcw_gsm1+self.tcw_gsm2+self.tcw_gsm3,self.tcw_gsm_fee1+self.tcw_gsm_fee2+self.tcw_gsm_fee3)  + ";流量超套" + str(gprs) + "次，"+ self.product_over_gprs(self.tcw_gprs1+self.tcw_gprs2+self.tcw_gprs3,self.tcw_gprs_fee1+self.tcw_gprs_fee2+self.tcw_gprs_fee3)
            level = 1 + int((gsm_fee+gprs_fee)/20.0)
            label_level["three_month_over"] =level
        elif gprs > 0:
            label_script["three_month_over"] =  "流量超套" + str(gprs) + "次，" 
            + self.product_over_gprs(self.tcw_gprs1+self.tcw_gprs2+self.tcw_gprs3,self.tcw_gprs_fee1+self.tcw_gprs_fee2+self.tcw_gprs_fee3)
            level = 1 + int((gprs_fee)/20.0)
            label_level["three_month_over"] =level
        elif gsm > 0:
            label_script["three_month_over"] = "观察到你近三月语音流量使用情况，" + "语音超套" + str(gsm) + "次，" 
            + self.product_over_gsm(self.tcw_gsm1+self.tcw_gsm2+self.tcw_gsm3,self.tcw_gsm_fee1+self.tcw_gsm_fee2+self.tcw_gsm_fee3) 
            level = 1 + int((gsm_fee)/20.0)
            label_level["three_month_over"] =level
        if self.is_cur_month_gprs_will_over() and self.is_cur_month_gsm_will_over():
            label_script["cur_month_will_over"] = "观察到你当月语音流量使用情况；" + "语音已使用"+self.conver_time(self.gpsm_all) +"；还剩余" + self.conver_time(self.gsm_residua) 
            + "；流量已使用"+self.conver_m(self.gprs_all) +"；还剩余" + self.conver_m(self.gprs_residua)
            level = int((self.avg_day_gprs*self.suf_cur_day_count)/self.gprs_residua + (self.avg_day_gsm*self.suf_cur_day_count)/self.gsm_residua)
            label_level["cur_month_will_over"] =level
        elif self.is_cur_month_gprs_will_over():
            label_script["cur_month_will_over"] = "观察到你当月语音流量使用情况；" + "流量已使用"+self.conver_m(self.gprs_all) +"；还剩余" + self.conver_m(self.gprs_residua)
            level = int((self.avg_day_gprs*self.suf_cur_day_count)/self.gprs_residua )
            label_level["cur_month_will_over"] =level
        elif self.is_cur_month_gsm_will_over():
            label_script["cur_month_will_over"] = "观察到你当月语音流量使用情况；" + "语音已使用"+self.conver_time(self.gsm_all) +"；还剩余" + self.conver_time(self.gsm_residua) 
            level = int((self.avg_day_gsm*self.suf_cur_day_count)/self.gsm_residua)
            label_level["cur_month_will_over"] =level
        if self.is_over_activity() >0:
            label_script["activate_over"] = "观察到你参与的活动情况；上月活动到期了" + str(self.pre_day_count) + "个;本月活动到期了" + str(self.current_month_count)+ "个;次日将到期" + str(self.next_day_count) + "个;下月将到期" +str(self.next_month_count) + "个."
            level = 0
            if self.pre_day_count>0 or self.next_day_count>0 or self.next_month_count>0 or self.current_month_count>0:
                level = 1
            label_level["activate_over"] = 1
        #print(label_words)
        return label_script,label_level,script_label_dic,label_words,name_label_dic
        
if __name__=='__main__':
    print("check predict.....")
    script_label_dic,name_label_dic = load_conf_labels()
    #all_labels = load_conf_labels()
    #str1="上月参与了主套餐优惠减免活动"
    #str2="套餐使用语音剩余量偏多而流量偏少"
    #str2="上月参与了主套餐优惠减免活动"
    #merge_two_str(str1,str2)
    #merge_str()
    #print(all_labels)
